package com.daocao.hua.api.requestInfo;

import com.daocao.hua.api.Api;
import com.daocao.hua.api.bean.LoanDetailBean;
import com.daocao.hua.api.callback.LoanDetailContract;
import com.daocao.hua.util.Network;
import com.daocao.hua.util.RxLifeUtil;
import com.daocao.hua.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class LoanDetailRequest extends BaseRequest<LoanDetailContract.View> implements LoanDetailContract.Presenter<LoanDetailContract.View> {

    public static LoanDetailRequest create() {
        return new LoanDetailRequest();
    }


    @Override
    public void getBankList() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        Api.api_service.getBankList().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getBankListSuccess(result);
                });
    }

    @Override
    public void getLoanDetail(String id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        LoanDetailBean bean = new LoanDetailBean();
        bean.id = id;
        Api.api_service.getDealDetail(bean).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getLoanDetailSuccess(result);
                });
    }
}
